<?php
	if(extension_loaded('gd')) {
	//echo '你可以使用gd<br>';
	//foreach(gd_info() as $cate=>$value)
    //echo "$cate: $value<br>";
	}else
	{
	  echo '你没有安装gd扩展';
	}
	$x = $_POST['x1'];//客户端选择区域左上角x轴坐标    
	$y = $_POST['y1'];//客户端选择区域左上角y轴坐标    
	$w = $_POST['w'];//客户端选择区 的宽    
	$h = $_POST['h'];//客户端选择区 的高   
	$userID = $_POST['userID'];
	$oriFile = $_POST['oriFile'];
	//echo "x=$x  ";
	//echo "y=$y  ";
	//echo "w=$w  ";
	//echo "h=$h  ";
	//echo "userID = $userID  ";
	//echo "oriFile = $oriFile  ";
	//$filename = "uploads/".$userID.".jpg";//图片的路径   kakassi add  暂时只能支持jpg 其他格式以后再说

	$im = @imagecreatefromjpeg($oriFile);// 读取需要处理的图片 
	if(!$im)
	{
		//$im = imagecreatefrombmp($oriFile);//我电脑上的php版本好像不到4 所以不支持bmp 但是png 和 gif应该都是支持的
		$im = @imagecreatefrompng($oriFile);
	}
	if(!$im)
	{
		$im = @imagecreatefromgif($oriFile);
	}
	if(!$im)
	{
		echo "false";
		return;
	}
	$newim = imagecreatetruecolor(150, 150);//产生新图片 100 100 为新图片的宽和高
	imagecopyresampled($newim, $im, 0, 0, $x, $y, 150, 150, $w, $h); 	
	//imagecopyresampled($newim, $im, 0, 0, 300, 0, 150, 150, 300, 300); 
	//imagejpeg($newim, $filename);
        $pathinfo = pathinfo($oriFile);
        $filename = $pathinfo['filename'];
        $ext = $pathinfo['extension'];
		//$newfilename = 'uploads/'.$userID.'.'.$ext;
		//去掉后缀名 以适应各种格式的兼容
		$newfilename = 'uploads/'.$userID;
	imagejpeg($newim, $newfilename); 
	imagedestroy($im);    
	imagedestroy($newim);   
	echo "true";
?>